/*
 * Copyright (c) 2018 maoyan.com
 * All rights reserved.
 *
 */
package com.darren.euc.service.impl;

import com.darren.euc.dao.CityDao;
import com.darren.euc.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 在这里编写类的功能描述
 *
 * @author fangwenhao
 * @created 2018/3/14
 */
@Service
public class CityServiceImpl implements CityService {

    @Autowired
    private CityDao cityDao;


    @Override
    public List<Map> findEnableProvince(Map map) {

        String sql = "";
        if (map.get("province_id") != null){
            sql = "SELECT c.city_id,c.city_name FROM euc_cities c WHERE c.enable=1" +
                    " AND c.province_id="+map.get("province_id");
        }else {
            sql = "SELECT c.city_id,c.city_name FROM euc_cities c" +
                    "  LEFT JOIN euc_provinces p ON c.province_id=p.province_id" +
                    "  WHERE c.enable=1 AND p.enable=1";
        }
        return cityDao.getDataMapList(sql);
    }

    @Override
    public List<Map> findEnableProvinces() {

        String sql = "SELECT p.province_id,p.province_name FROM euc_provinces p WHERE p.enable=1";
        return cityDao.getDataMapList(sql);
    }
}
